{include file="header.html"}
<div class="title tc ml-30 mr-10">
	<h2>产品信息录入</h2>
</div>
<div class="content px-20">
<form name="myForm" id="myForm" action="/index.php?act=price&st=query_result" method="post">
	<section id="step1">
		<table class="my-10">
		    <tbody>
		        <tr>
		            <td class="pl-20">产品品种</td>
		            <td class="pl-15">
		            	<select name="product_id" class="w-150" id="produce_name">
		            	<option value="0">请选择</option>
		            	{foreach item=product from=$product_list}
		            		<option value="{$product.product_id}">{$product.produce_name}</option>
		            	{/foreach}
		            	</select>
		            	<input type="hidden" value="" name="product_name" id="product_id" />
					</td>
		        </tr>
		        <tr>
		            <td class="pl-20">材质基础</td>
		            <td class="pl-15">
		            	<select name="marerials" class="w-150" id="marerials">
		            	<option value='0'>请选择</option>
		            	</select>
					</td>
		        </tr>
				<tr>
		            <td class="pl-20">产品材质</td>
		            <td class="pl-15">
		            	<select name="marerial" class="w-150" id="marerial">
		            	<option value='0'>请选择</option>
		            	</select>
					</td>
		        </tr>
		        <tr>
		            <td class="pl-20">定价区域</td>
		            <td class="pl-15">
		            	<select name="area_price" class="w-150" id="area_price">
		            		<option value="0">请选择</option>
		            	</select>
					</td>
		        </tr>
		        <tr>
		            <td class="pl-20">运输方式</td>
		            <td class="pl-15">
		            	<select name="transport" class="w-150" id="transport">
		            		<option value="0">请选择</option>
		            	</select>
					</td>
		        </tr>		        
		        <tr id="transport_type" style="display:none">
		            <td class="pl-20" id="transport_type_label"></td>
		            <td class="pl-15">
		            	<select name="" class="w-150" id="sel_transport_type">
		            		<option value="0">请选择</option>
		            	</select>
					</td>
		        </tr>		        
		        <tr>
		            <td class="pl-20">产品数量</td>
		            <td class="pl-15"><input id="number" name="number" type="tel" class="w-90" /> 吨</td>
		        </tr>
		    </tbody>
		</table>
		<p class="tc"><button id="btn_submit" class="btn w-150 h-40" type="submit"> 提 交  </button></p>
	</section>
</form>
<script type="text/javascript">
var marerial = {};
$(function(){
	//选择商品互动
	$("#produce_name").on("change",function(){
		var produce_id = $("#produce_name").val();
		$("#product_id").val($("#produce_name option").not(function(){ return !this.selected }).text());
		if(produce_id == 0) {
			$("#marerials").html("<option value='0'>请选择</option>");
		} else {
			$.ajax({
				type:"GET",
				url:"/?act=price_query&st=get_data",
				data:{"product_id":produce_id},
				dataType:"json",
				timeout:15000,
				success:function(data) {
					if(typeof data.errCode != 'undefined') {
						if(data.errCode == '00') {
							var html = "<option value='0'>请选择</option>";
							var html2 = "<option value='0'>请选择</option>";
							if(typeof data.marerials != 'undefined') {
								var items = data.marerials;
								marerial = data.marerials;
								for(var key in items) {
									if(key == 0 && items[key].marerial != '') {
										var marerial_arr = eval("("+items[key].marerial+")");
										for(var ke in marerial_arr){
											html += "<option value='"+marerial_arr[ke]+"'>"+marerial_arr[ke]+"</option>";
										}
									}
									if(items[key].marerials != '') {
										html2 += "<option value='"+items[key].marerials+"'>"+items[key].marerials+"</option>";
									}
								}
								if(data.price_list != ''){
									price_list_show(data.price_list);
								}
							}
							$("#marerial").html(html);
							$("#marerials").html(html2);
							
							if(typeof data.area_price != 'undefined' && data.area_price != null) {
								var items = data.area_price;
								html = "<option value='0'>请选择</option>";
								for(var key in items) {
									html += "<option value='"+items[key]+"'>"+items[key]+"</option>";
								}
							}
							$("#area_price").html(html);
							
							if(typeof data.transport != 'undefined' && data.transport != '') {
								var items = data.transport;
								var transport_val = items.val;
								var transport_name = items.name;
								var length = transport_val.length;
								html = "<option value='0'>请选择</option>";
								for(var key=0;key<length;key++) {
									html += "<option value='"+transport_val[key]+"'>"+transport_name[key]+"</option>";
								}
							}
							$("#transport").html(html);
						}
					}
				},
				error:function() {
					/* alert("网络繁忙，请稍后再试！");
					return false; */
				}
			});
		}
	});
	//材质基础和材质切换
	$("#marerials").on("change", function(){
		var _value = $(this).val();
		for(var key in marerial){
			if(_value == marerial[key].marerials){
				var html = "<option value='0'>请选择</option>";
				var marerial_arr = eval("("+marerial[key].marerial+")");
				for(var ke in marerial_arr){
					html += "<option value='"+marerial_arr[ke]+"'>"+marerial_arr[ke]+"</option>";
				}
				$("#marerial").html(html);
			}
		}
	});
	
	$("#transport").on("change",function(){
		var transport_type = $(this).val();
		if(transport_type == 0) {
			$("#transport_type").hide();
			$("#transport_type_label").html("");
			$("#sel_transport_type").attr("name","");
			$("#sel_transport_type").html("<option value='0'>请选择</option>");
		} else {
			var product_id = $("#produce_name").val();
			var transport_type_a = {"motor":"汽运","shipping":"船运","motor_shipping":"汽船联运","train":"火运"};
			$("#transport_type_label").html(transport_type_a[transport_type]);
			$("#sel_transport_type").attr("name",transport_type);
			$.ajax({
				type:"GET",
				url:"/?act=price&st=get_transport_area",
				data:{"product_id":product_id,"filed":transport_type},
				dataType:"json",
				timeout:15000,
				success:function(data) {
					if(typeof data.errCode != 'undefined') {
						if(data.errCode == '00') {
							var html = "";
							if(typeof data.items != 'undefined' && data.items != "") {
								var items = data.items;
								if(items.length > 1) {
									html = "<option value='0'>请选择</option>";
								}
								for(var key in items) {
									html += "<option value='"+items[key]+"'>"+items[key]+"</option>";
								}
							}
							$("#sel_transport_type").html(html);
						}
					}
					$("#transport_type").show();
				},
				error:function() {
					/* alert("网络繁忙，请稍后再试！");
					return false; */
				}
			});
		}
	});
	
});
function price_list_show($price_list){
	var html = "";
	var start = 7;
	var len = $("table tbody tr").length;
	for(var key in $price_list){
		html += '<tr><td class="pl-20">'+$price_list[key].price_name+'</td><td class="pl-15"><select name="price_list[]" class="w-150" id="transport"><option value="0">请选择</option>';
		for(var ke in $price_list[key].childs){
			html += '<option value="'+$price_list[key].childs[ke].price_name+'">'+$price_list[key].childs[ke].price_name+'</option>';
		}
		html +='</select></td></tr>';
	}
	for(;start < len; start++){
		$("table tbody tr").eq(start).remove();
	}
	$("table tbody").append(html);
}
</script>
</div>
{include file="footer.html"}